
var menuTypeRes = new Array();

var menuTypes = {};

/**
 * @description 获取菜单类型和类型名称.<br>
 * @author zcg.<br>
 * @date 2019-03-07.<br>
 */
function getMenuContrType(adminPath){
	var res = new Array();
	var url = '/sys/menu/getMenuContrType';
	var menuId = window.localStorage? localStorage.getItem("nid"): Cookie.read("nid");
	$.ajax({
		url:adminPath + url,
		type:'post',
		dataType:'json',
		async:false,
		data:{menuId:menuId},
		success:function(data) {
			res = data;
			menuTypeRes = data;
		}
	});
	return res;
}

/**
 * @description 获取菜单控制类型.<br>
 * @params treeNode ztree的节点.<br> 
 * @author zcg.<br>
 * @date 2019-03-07.<br>
 */
function getMenuCtrlTypes(treeNode){
	if(treeNode.extend.isOrg){
		menuTypes = checkIsAllow(treeNode.type.split(','));
	}else{
		menuTypes = checkIsAllow([]);
	}
	return menuTypes;
}

/**
 * @description 检测当前组织是否在该菜单控制范围内.<br>
 * @author zcg.<br>
 * @date 2019-03-07.<br>
 */
function checkIsAllow(orgTypes){
	var res = {flag:true,msg:'未知'};
	if(menuTypeRes.types&&orgTypes){
		var types = menuTypeRes.types;
		var typeName = menuTypeRes.typeNames.join('、');
		var flag = Array.intersect(types,orgTypes); 
		res.flag = flag;
		res.msg = typeName;
	}
	return res;
}

/**
 * @description 求两个数组的交集.<br>
 * @author zcg.<br>
 * @date 2019-03-07.<br>
 */
Array.intersect = function(a, b){  
	var flag = false;
	a.forEach(function(val){
		if(b.contains(val)){
			flag = true;
		}
	});
	return flag;
};

/**
 * @description Array扩展包含函数,获取是否包含.<br>
 * @author zcg.<br>
 * @date 2019-03-07.<br>
 */
Array.prototype.contains = function (obj) {  
    var i = this.length;  
    while (i--) {  
        if (this[i] === obj) {  
            return true;  
        }  
    }  
    return false;  
}
